package com.njtoyo.taxi.admin.logic.business.simple_call;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.njtoyo.taxi.admin.mapper.master.entity.RideTransactionLog;
import com.njtoyo.taxi.admin.mapper.master.mapper.RideTransactionLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

@Service
public class RideTransactionLogLogic {
    @Autowired
    private RideTransactionLogMapper rideTransactionLogMapper;

    public RideTransactionLog getLogByRideOrderId(Long rideOrderId) {
        List<RideTransactionLog> list = new LambdaQueryChainWrapper<>(rideTransactionLogMapper)
                .eq(RideTransactionLog::getRideOrderId, rideOrderId)
                .orderByDesc(RideTransactionLog::getId)
                .last("limit 1")
                .list();

        if (Objects.nonNull(list)) {
            Optional<RideTransactionLog> first = list.stream().findFirst();
            if (first.isPresent()) {
                return first.get();
            }
        }

        return null;
    }
}
